package com.gdk.ksoft.assembly.utils.extensions;

import android.text.TextUtils;

import net.sourceforge.pinyin4j.PinyinHelper;

/**
 * Created by hel on 2014-12-24.
 * 字符串辅助类
 */
public class StringUtils {

    /**
     * 获取一组字符串的首字母
     * @param str
     * @return
     */
    public static String getFirstLetterString(String str){
        if(TextUtils.isEmpty(str)) return null;
        StringBuilder strBuilder = new StringBuilder();
        for(int i=0;i<str.length();i++){
            char ch = str.charAt(i);
            String[] value = PinyinHelper.toHanyuPinyinStringArray(ch);
            if(value!=null && value.length>0){
                strBuilder.append(value[0].charAt(0));
            }
        }
        return strBuilder.toString();
    }
}
